//
//  BCUserSvipHeaderContentView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/20.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCUserSvipHeaderContentView.h"

#import "BCUserSvipResponse.h"

#import "BCEyesButton.h"

@interface BCUserSvipHeaderContentView ()

@property (nonatomic, strong) CAGradientLayer *svipLayer;

/**
 *codeLabel
 */
@property (nonatomic, strong) QMUILabel *codeLabel;


/**
 *amountLabel
 */
@property (nonatomic, strong) QMUILabel *amountLabel;

/**
 *amountCaptionLabel
 */
@property (nonatomic, strong) QMUILabel *amountCaptionLabel;

/**
 *BCEyesButton
 */
@property (nonatomic, strong) BCEyesButton *eyesButton;

/**
 *appNameLabel
 */
@property (nonatomic, strong) QMUILabel *appNameLabel;

@end

@implementation BCUserSvipHeaderContentView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setSvipLayer];
        [self setupSubviews];
    }
    return self;
}
//
- (void)setSvipLayer {
    self.svipLayer = [CAGradientLayer layer];
    [self.layer addSublayer:self.svipLayer];
    //
    UIImage *svipImage = LOAD_IMAGE(@"super_vip_img");
    UIImageView *svipIV = [[UIImageView alloc] initWithImage:svipImage];
    [svipIV sizeToFit];
    self.svipLayer.frame = CGRectMake(15, 11, svipIV.frame.size.width, svipIV.frame.size.height);
    self.svipLayer.colors = @[(id)[UIColor redColor].CGColor,(id)[UIColor darkSubMainColor].CGColor,(id)[UIColor darkMainColor].CGColor];
    self.svipLayer.startPoint = CGPointZero;
    self.svipLayer.endPoint = CGPointMake(1, 1);
    self.svipLayer.mask = svipIV.layer;
    
    //
    UIImageView *bitCoin = [UIImageView new];
    bitCoin.image = LOAD_IMAGE(@"svip_bitcoin");
    [self addSubview:bitCoin];
    [bitCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(10.0);
        make.right.mas_equalTo(self).offset(-15.0);
    }];
}

- (void)setupSubviews {
    self.codeLabel = [QMUILabel new];
    self.codeLabel.textColor = [UIColor qmui_colorWithHexString:@"#444957"];
    self.codeLabel.font = [UIFont systemFontOfSize:30 weight:UIFontWeightMedium];
    [self addSubview:self.codeLabel];
    [self.codeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(15.0);
        make.bottom.mas_equalTo(self.mas_centerY);
    }];
    self.codeLabel.canPerformCopyAction = true;
    self.codeLabel.menuItemTitleForCopyAction = BCLocalizedKey(@"general_copy");
    //复制
    self.codeLabel.didCopyBlock = ^(QMUILabel *label, NSString *stringCopied) {
        [[UIPasteboard generalPasteboard] setString:stringCopied];
    };
    
    //
    self.amountLabel = [QMUILabel new];
    self.amountLabel.font = [UIFont systemFontOfSize:20.0 weight:UIFontWeightRegular];
    self.amountLabel.textColor = [UIColor qmui_colorWithHexString:@"#444957"];
    [self addSubview:self.amountLabel];
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.codeLabel);
        make.bottom.mas_equalTo(self).offset(-20.0);
    }];
    //
    self.amountCaptionLabel = [QMUILabel new];
    self.amountCaptionLabel.textColor = [UIColor qmui_colorWithHexString:@"#444957"];
    self.amountCaptionLabel.font = [UIFont systemFontOfSize:11 weight:UIFontWeightRegular];
    [self addSubview:self.amountCaptionLabel];
    [self.amountCaptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.amountLabel);
        make.bottom.mas_equalTo(self.amountLabel.mas_top).offset(-11.0);
    }];
    //
    self.eyesButton = [BCEyesButton new];
    self.eyesButton.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 16, 8);
    [self addSubview:self.eyesButton];
    [self.eyesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.amountCaptionLabel.mas_right);
        make.centerY.mas_equalTo(self.amountCaptionLabel);
    }];
    self.eyesButton.open = false;
    [self.eyesButton addTarget:self action:@selector(eyesButtonDidClickedAction) forControlEvents:UIControlEventTouchUpInside];
    
    //
    self.appNameLabel = [QMUILabel new];
    self.appNameLabel.textColor = [UIColor qmui_colorWithHexString:@"#80464A59"];
    self.appNameLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
    [self addSubview:self.appNameLabel];
    [self.appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-15.0);
        make.centerY.mas_equalTo(self.amountLabel.mas_centerY);
    }];
}

- (void)eyesButtonDidClickedAction {
    self.eyesButton.open = !self.eyesButton.open;
    //
    self.svipData = self.svipData;
}


- (void)setSvipData:(BCUserSvipData *)svipData {
    _svipData = svipData;
    //
    self.codeLabel.text = svipData.data.share_code;
    
    //
    NSString *commissionCaption = svipData.flow.commission;
    self.amountCaptionLabel.text = [commissionCaption stringByAppendingFormat:@"(%@)",svipData.buy.cur_sign];
    //
    NSString *commission = svipData.data.commission;
    if (self.eyesButton.open) {
        self.amountLabel.text = commission;
    }else {
        NSInteger commissionlength = commission.length;
        NSString *xinString = @"";
        for (int i=0; i<commissionlength; i++) {
            xinString = [xinString stringByAppendingString:@"*"];
        }
        self.amountLabel.text = xinString;
    }
    
    //
    self.appNameLabel.text = BCLocalizedKey(@"BCNormalDisplayName");
}

@end
